package arrage;

import java.util.ArrayList;
import java.util.Random;

public class homework4 {
    public static void main(String[] args) {
        ArrayList<Integer> ai = new ArrayList<>();
        Random ri = new Random();
        for (int i = 0; i < 20; i++) {
            ai.add(ri.nextInt(30) + 1);
        }
        System.out.println("所有的随机数有");
        System.out.println(ai);

        System.out.println("其中偶数有");
        System.out.println(shaxuan(ai));
    }
    public static ArrayList<Integer> shaxuan(ArrayList<Integer> ai) {
        ArrayList<Integer> atwo = new ArrayList<>();
        for (int i = 0; i < ai.size(); i++) {
            if (ai.get(i) % 2 == 0) {
                atwo.add(ai.get(i));
            }
        }
        return atwo;
    }

}



